İOS Rehber Çekme
09.05.2015 - 11:35
İos ile telefonun rehberinde kayıtlı olan numaraları çekmek istiyorum yardımcı olabilir misiniz?
10
Görüntülenme
0 Beğeni
ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);
if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
ABAddressBookRef addressBook = ABAddressBookCreate( );
});
}
else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {
CFErrorRef *error = NULL;
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, error);
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex numberOfPeople = ABAddressBookGetPersonCount(addressBook);
addressBookNum =[[NSString alloc] init];
for(int i = 0; i < numberOfPeople; i++) {
ABRecordRef person = CFArrayGetValueAtIndex( allPeople, i );
ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
[[UIDevice currentDevice] name];
// NSLog(@"\n%@\n", [[UIDevice currentDevice] name]);
firstName = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonFirstNameProperty));
lastName = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonLastNameProperty));
for (CFIndex i = 0; i < ABMultiValueGetCount(phoneNumbers); i++) {
NSString *phoneNumber = (__bridge_transfer NSString *) ABMultiValueCopyValueAtIndex(phoneNumbers, i);
addressBookNum = [addressBookNum stringByAppendingFormat: @" %@ %@ :%@ ",firstName , lastName ,phoneNumber];
}
}
NSLog(@" %@ %@ AllNumber : %@ " , firstName , lastName , addressBookNum);
}
else {
}
.h dosyasında tanımlanacak.
@property NSString *addressBookNum ;
@property NSString *firstName ;
@property NSString *lastName ;
sonra .m dosyasında
@synthesize addressBookNum, firstName,lastName;
Lazım olan olursa :)
Bu şekilde Okudum Tesekkur ederim
Burada anlatılan örnekten yararlanarak yapabilirsiniz:
http://www.raywenderlich.com/63885/address-book-tutorial-in-ios